package 线程同步.不安全的案例;

import java.util.ArrayList;
import java.util.List;

public class 线程不安全的集合 {
    public static void main(String[] args) throws InterruptedException {
        List<String> sum = new ArrayList<String>();//ArrayList不安全
        for (int i = 0; i < 100000; i++) {
            new Thread(()->{
                sum.add(Thread.currentThread().getName());
            }).start();
        }
        Thread.sleep(3000);
        System.out.println(sum.size());
    }
}
